package com.graduation.mybatis.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.graduation.mybatis.bean.UserLike;
import com.graduation.mybatis.service.UserLikeService;
import com.graduation.mybatis.mapper.UserLikeMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
* @author 23726
* @description 针对表【user_like】的数据库操作Service实现
* @createDate 2025-05-01 17:11:33
*/
@Service
public class UserLikeServiceImpl extends ServiceImpl<UserLikeMapper, UserLike>
    implements UserLikeService{

    @Resource
    private UserLikeMapper userLikeMapper;

    public void addLike(Long userId, Long newsId) {
        userLikeMapper.insertLike(userId, newsId);
        // 更新资讯点赞数
        userLikeMapper.updateNewsCommentCount(newsId, 1);
    }

    public void removeLike(Long userId, Long newsId) {
        userLikeMapper.deleteLike(userId, newsId);
        // 更新资讯点赞数
        userLikeMapper.updateNewsCommentCount(newsId, -1);
    }
}




